﻿/*
 * 文件名称：
 * 程序员：huangsb
 * 创建时间：2008/05/10
 * 
 * 功能说明：站点配置
 * 
 * 修改人员：
 * 
 * 修改日期：
 * 
 * 修改记录：
 */

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Whir_System_Module_Config_SiteConfig : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        RoleHelper.IsLogin();    //登录判断

        if (!IsPostBack)
        {
            //string xmlPath = Server.MapPath(Whir.Common.Settings.GetString("XmlPath") + "SiteConfig.xml");
            string xmlPath = Server.MapPath("~/" + Whir.Common.Settings.GetString("XmlPath") + "SiteConfig.xml");
            Type type = typeof(Whir.Config.Model.SiteConfig);
            Whir.Config.Model.SiteConfig model = (Whir.Config.Model.SiteConfig)Whir.Common.XmlHelper.DeserializeObject(xmlPath, type);         //反序列化

            this.txtSiteTitle.Text = model.siteTitle;
            //显示Logo图片
            EzUpload1.Value = model.logoUrl;
            EzUpload1.PreViewUrl = Whir.Common.Settings.GetPicServer() + model.logoUrl;

            //显示登录图片
            EzUpload2.Value = model.bannerUrl;
            EzUpload2.PreViewUrl = Whir.Common.Settings.GetPicServer() + model.bannerUrl;

            this.txtSiteICP.Text = model.siteICP;
            //model.ICPUrl = "";
            this.txtMetaKey.Text = model.metaKey;
            this.txtMetaDesc.Text = model.metaDesc;
            this.txtCopyright.Text = model.copyright;
            this.txtADCatalog.Text = model.ADCatalog;
            this.rblIsAllowUpload.SelectedValue = model.isAllowUpload;
            this.rblEditor.SelectedValue = model.Editor;
        }
    }

    //修改
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        Whir.Config.Model.SiteConfig model = new Whir.Config.Model.SiteConfig();

        model.siteTitle = this.txtSiteTitle.Text;

        //显示Logo图片
        string logoUrl = EzUpload1.Value;
        if (EzUpload1.DefaultMode == Lib_ezModule_ezUpload.ModeState.Upload)
        {
            if (EzUpload1.inputFile.HasFile)
            {
                //string path = Page.Server.MapPath("~/UploadFiles/image/");
                string path = Server.MapPath("~/" + Whir.Common.Settings.GetPicServer());
                    //Page.Server.MapPath("~/UploadFiles/image/");



                string destPath = System.IO.Path.Combine(path, logoUrl);
                EzUpload1.inputFile.MoveTo(destPath, Brettle.Web.NeatUpload.MoveToOptions.Overwrite);
            }
        }
        model.logoUrl = logoUrl;

        //显示登录图片
        string logoUrl2 = EzUpload2.Value;
        if (EzUpload2.DefaultMode == Lib_ezModule_ezUpload.ModeState.Upload)
        {
            if (EzUpload2.inputFile.HasFile)
            {
                string path = Page.Server.MapPath("~/UploadFiles/image/");


                string destPath = System.IO.Path.Combine(path, logoUrl2);
                EzUpload2.inputFile.MoveTo(destPath, Brettle.Web.NeatUpload.MoveToOptions.Overwrite);
            }
        }
        model.bannerUrl = logoUrl2;

        model.siteICP = this.txtSiteICP.Text;

        model.ICPUrl = "";

        model.metaKey = this.txtMetaKey.Text;
        model.metaDesc = this.txtMetaDesc.Text;
        model.copyright = this.txtCopyright.Text;
        model.ADCatalog = this.txtADCatalog.Text;
        model.isAllowUpload = this.rblIsAllowUpload.SelectedValue;
        model.Editor = this.rblEditor.SelectedValue;

        //string xmlPath = Server.MapPath(Whir.Common.Settings.GetString("XmlPath") + "SiteConfig.xml");
        string xmlPath = Server.MapPath("~/"+Whir.Common.Settings.GetString("XmlPath") + "SiteConfig.xml");

        Type type = typeof(Whir.Config.Model.SiteConfig);
        Whir.Common.XmlHelper.SerializerObject(xmlPath, type, model);               //序列化

        this.OLAdd();    //操作日志
    }

    //操作日志
    protected void OLAdd()
    {
        Whir.Log.Model.Whir_OperateLog model = new Whir.Log.Model.Whir_OperateLog();
        model.title = "站点信息";
        model.operateType = 2;      //修改
        model.operateResult = true;
        model.operateDesc = "修改站点信息";

        Whir.Log.OperateLog.Add(model);
    }
}
